<?php
	$names_list = array(); 
	$files_list = array(); 
	$max_file_len = 0; 
	$data = parse_ini_file("../../configs/smileys.ini", true); 
	foreach ($data as $cat => $smileys) {
		foreach ($smileys as $file => $names_str) {
			$max_file_len = max($max_file_len, strlen($file)); 
			$names = explode(' ', $names_str); 
			foreach ($names as $name) {
				$names_list[] = sprintf("0x%08X", crc32($name)); 
				$files_list[] = addcslashes($file, "\n\"\r"); 
			}
		}
	}
	
	//	$total = count($names_list); 
	//	for ($i = 0; $i < $total; ++$i) {
	//		for ($j = $i + 1; $j < $total; ++$j) {
	//			if ($names_list[$i] == $names_list[$j])
	//				echo $names_list[$i]."\n"; 
	//		}
	//	}
	
	// echo "a = ".count($names_list)."\n"; 
	// $names_list = array_unique($names_list); 
	// echo "b = ".count($names_list)."\n"; 
	
	$header = ""; 
	$header .= "const unsigned int TextPreprocessor::smileys_names[".count($names_list)."] = {\n"; 
	$header .= "\t".implode(", \n\t", $names_list)."\n"; 
	$header .= "}; \n\n"; 
	
	$header .= "const char TextPreprocessor::smileys_files[".count($files_list)."][".($max_file_len + 1)."] = {\n"; 
	$header .= "\t\"".implode("\", \n\t\"", $files_list)."\"\n"; 
	$header .= "}; \n"; 
	
	file_put_contents("../src/Text/_smileys_array.cpp", $header); 
	
	$header = ""; 
	$header .= "static const unsigned int smileys_names[".count($names_list)."]; \n"; 
	$header .= "static const char smileys_files[".count($files_list)."][".($max_file_len + 1)."]; \n"; 
	
	file_put_contents("../src/Text/_smileys_array.hpp", $header); 
	
